// let baseSsoUrl = 'http://172.16.90.202:80';
export const baseSsoUrl = 'http://wl.antaigroup.com:8795';
export const baseUrl = "http://wl.antaigroup.com:8795"
// let baseUrl = "http://192.168.0.159:8080"
// let baseUrl = "http://172.16.90.202"
export const myRequest = (options) => { //暴露一个function：myRequest，使用options接收页面传过来的参
	//加载loading
	if (options.showLoading) {
		uni.showLoading({
			title: options.maskTitle || '加载中',
			mask: options.mask
		})
	}
	//异步封装接口，使用Promise处理异步请求
	return new Promise((resolve, reject) => {
		let header = options.header || {}
		if (uni.getStorageSync("header")) {
			header = {
				...JSON.parse(uni.getStorageSync("header")),
				...options.header
			}
		}
		if (options.url.includes('apiId') && !options.url.includes('pageNum')) {
			options.url = options.url + '&pageNum=1&pageSize=50'
		}
		// #ifdef APP-PLUS
		options.url = baseUrl + options.url
		// #endif
		options.data = {
			...options.data,
			...{
				terminalCode: "app",
				appVesion: uni.getStorageSync("appVersion")
			}
		};
		uni.request({ //发送请求
			url: options.url,
			method: options.method || 'POST', //接收请求的方式,如果不传默认为POST
			data: options.data || {}, //接收请求的data,不传默认为空
			header: header || {},
			dataType: options.dataType,
			timeout: 15000,
			success: (res) => { //数据获取成功
				if (res.data.status == 'succeed') {
					resolve(res) //成功,将数据返回
				} else {
					reject(res.data.message)
				}
			},
			fail: (err) => { //失败操作
				uni.showToast({
					duration: 2000,
					title: "网络异常!",
					icon: "error",
				})
				reject(err)
			},
			complete: () => {
				//隐藏loading
				if (options.showLoading) {
					uni.hideLoading()
				}
			}
		})
	})
}

//暴露文件上传的接口
export const myFileRequest = (options) => { //暴露一个function：myRequest，使用options接收页面传过来的参数
	if (options.showLoading) {
		uni.showLoading({
			title: options.maskTitle || '加载中',
			mask: options.mask
		})
	}
	return new Promise((resolve, reject) => {
		let header = options.header || {}
		if (uni.getStorageSync("header")) {
			header = {
				...JSON.parse(uni.getStorageSync("header")),
				...options.header
			}
		}
		// #ifdef APP-PLUS
		options.url = baseUrl + options.url
		// #endif
		//异步封装接口，使用Promise处理异步请求
		uni.uploadFile({ //发送请求
			url: options.url,
			filePath: options.filePath,
			name: "",
			files: options.files,
			formData: options.formData,
			header: header || {},
			timeout: 15000,
			success: (res) => { //数据获取成功
				if (res.data.status == 'succeed') {
					resolve(res) //成功,将数据返回
				} else {
					reject(res.data.message)
				}
			},
			fail: (err) => { //失败操作
				uni.showToast({
					duration: 2000,
					title: "网络异常!",
					icon: "error",
				})
				reject(err)
			}
		})
	})
}

//功能：暴露sso的接口
export const mySsoRequest = (options) => { //暴露一个function：myRequest，使用options接收页面传过来的参数
	if (options.showLoading) {
		uni.showLoading({
			title: options.maskTitle || '加载中',
			mask: options.mask
		})
	}
	return new Promise((resolve, reject) => {
		let header = options.header || {}
		if (uni.getStorageSync("header")) {
			header = {
				...JSON.parse(uni.getStorageSync("header")),
				...options.header
			}
		}
		// #ifdef APP-PLUS
		options.url = baseSsoUrl + options.url
		// #endif
		//异步封装接口，使用Promise处理异步请求
		uni.request({ //发送请求
			url: options.url,
			method: options.method || 'GET', //接收请求的方式,如果不传默认为GET
			data: options.data || {}, //接收请求的data,不传默认为空
			header: header || {},
			dataType: options.dataType,
			timeout: 15000,
			success: (res) => { //数据获取成功
				if (res.data.status == 'succeed') {
					resolve(res) //成功,将数据返回
				} else {
					reject(res.data.message)
				}
			},
			fail: (err) => { //失败操作
				uni.showToast({
					duration: 2000,
					title: "网络异常!",
					icon: "error",
				})
				reject(err)
			},
			complete: () => {
				uni.hideLoading()
			}
		})
	})
}